<template>
    <el-dialog style="margin-left: 30vh; margin-top: 25vh;" width="40%" title="购买保险" :visible.sync="dialogVisible" :close-on-click-modal="false">
        <el-form class="ruleForm" ref="ruleForm" :model="form" label-width="80">
            <el-form-item label="保险受益人" prop="Insurance">
                <el-select v-model="form.member_id" placeholder="请选择保险受益人" @change="insuranceChange">
                    <el-option v-for="item in this.insuranceList" :key="item.mechanism" :label="item.mechanism" :value="item.member_id"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button size="small" @click="dialogVisible = false">取 消</el-button>
            <el-button size="small" type="primary" @click="submit">确 定</el-button>
        </div>
    </el-dialog>
</template>

<script>
import { insuranceCreate,orderList } from "@/api/order";
export default {
    props: {
        insuranceList:Array,
        orderId:Number
    },
    data() {
        return {
            form: {
                member_id:"",  
				orderNo:"",
            },
            dialogVisible: false
        }
    },
    methods: {
        submit() {
            this.$refs['ruleForm'].validate((valid) => {
                if (valid) {
                    const params={...this.form}
                    console.log("this.form=>",{...this.form});
                insuranceCreate(params).then(res => {
					console.log(res);
                    this.dialogVisible = false;
                    this.$emit('getList', true);
                })
                } else {
                this.$message({
                    message: "请检查表单错误",
                    type: "error"
                });
                return false;
                }
            });
        },
        insuranceChange(val){
            this.form.member_id=val
        }
    },
    watch: {
    dialogVisible(val) {
      if (val) {
        this.form.member_id = this.member_id;
      } else {
        this.$refs['ruleForm'].resetFields();
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.type_tip {
    color: #999999;
    line-height: 22px;

    span {
        color: #ff4146;
    }
}
</style>
